package cn.sy.exception;

import cn.sy.dto.ResponseDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalHandler {
    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ResponseEntity<ResponseDto> handleAnyException(Exception exception) {
        log.error("未知异常", exception);
        return ResponseEntity.status(HttpStatus.BAD_REQUEST)
                .body(new ResponseDto("400", exception.getMessage()));
    }
}
